<?php
namespace App\Services\Goods;

use App\Services\Goods\Goods\GoodsLogic;

/**
 * Class Goods 商品服务
 * @package App\Services\Goods
 */
class Goods
{
    /*商品列表*/
    public function goodsList($data): array
    {
        $data = init_array($data, ['keywords'=>'']);
        return (new GoodsLogic())->goodsList($data);
    }

    /*最新商品列表*/
    public function newGoodsList(): array
    {
        return (new GoodsLogic())->newGoodsList();
    }
    /*传商品id和数量返回多少价格*/
    public function goodsPrice($data): array
    {
        $data = init_array($data, ['id'=>0, 'number'=>0]);
        return (new GoodsLogic())->goodsPrice($data);
    }

    /*商品详情*/
    public function goodsInfo($data): array
    {
        $data = init_array($data, ['id'=>0]);
        ValidateGoods::checkValidate($data, ['id']);
        return (new GoodsLogic())->goodsInfo($data);
    }
    /*增*/
    public function addGoods($data): array
    {
        $data = init_array($data, ['title'=>'', 'desc'=>'', 'price'=>0, 'remain'=>0, 'img_url'=>'']);
        ValidateGoods::checkValidate($data, ['title', 'desc', 'price', 'remain', 'img_url']);
        return (new GoodsLogic())->addGoods($data);
    }

    /*删*/
    public function delGoods($data): array
    {
        $data = init_array($data, ['id'=>0]);
        ValidateGoods::checkValidate($data, ['id']);
        return (new GoodsLogic())->delGoods($data);
    }

    /*改*/
    public function altGoods($data): array
    {
        $data = init_array($data, ['id'=>0,'title'=>'', 'desc'=>'', 'price'=>0, 'remain'=>0, 'img_url'=>'']);
        ValidateGoods::checkValidate($data, ['id','title', 'desc', 'price', 'remain','img_url']);
        return (new GoodsLogic())->altGoods($data);
    }


}
